# 1. 导包
import jsonschema

# 2. 准备校验规则,
schema = {
    "type": "object",
    "properties": {

        "success": {"const": True},
        "code": {"const": 9999},
        "message": {"type": "string"},
        "money": {"type": "number"},
        "address": {"type": "null"},
        "data": {"type": "object",
                 "properties": {
                     "name": {"type": "string"},
                     "age": {"type": "integer"},
                     "sex": {"type": "string"}
                 },
                 "required": ["name", "age"]

                 },
        "luckyNumber": {"type": "array"},

    },
    "required": ["success", "message", "data"]
}
# 3. 准备待校验数据
json_data = {
    "success": True,
    "code": 9999,
    "message": "操作成功",
    "money": 6.66,
    "address": None,
    "data": {
        "name": "tom",
        "age": 19,
        "sex": "女"
    },
    "luckyNumber": [6, 8, 9]
}
# 4. 调用 validate() 校验
res = jsonschema.validate(instance=json_data, schema=schema)
# 5. 查看校验结果
print(res)
